function incel=savecell(infocell,fpath,opath,fname); 
% function incel=savecell(infocell,fpath,opath,fname);
% Writes a cell into an output file automatically determining 
% the columns formats
%
% Inputs 
% -----
% infocell  = cell to be saved
% fpath     = Root Path where mfiles stored 
% opath     = Output Path 
% fname     = filename for storage
%
% Output
% ------
% incel    incel.fid contains the file indicator 
%          If file to write cannot be opened meassage appears on screen 
% AJ 10/1/03 
%
% Note:  FPATH input is redundant, can have any value 
%        Just left in to avoid changing all codes...that call it. 
% Create Vector of Format Characters 

fpath = cd;

fname = [fname,'.txt']; 

[m,n]=size(infocell); 
fmat=zeros(1,n);
kk=1; 
for kk=1:n  
    cols=infocell(:,kk);
    fmat(kk)=size(char(cols),2); 
end
fmat(1)=-fmat(1); 
cd(opath); 
incel.fid=fopen(fname,'w');
cd(fpath); 
if incel.fid < 1 
    disp(['Could not save ',fname,'in ',opath])
else
incel.fmat=fmat; 
writecell(infocell,incel); 
cd(opath);
success =fclose(incel.fid); 
if success ~= 0 
    warning('Could not save file');
    fclose('all'); 
end
cd(fpath);
end